package com.shine.icis.action;

import com.shine.cotrun.sql.QueryParameters;
import com.shine.cotrun.web.comm.ListPage;
import com.shine.esim.struts.webutil.SessionParam;
import com.shine.icis.blo.ICompanyInfoService;
import com.shine.icis.config.SysConstants;
import com.shine.icis.dto.CompanyInfo;
import com.shine.icis.exception.ICISException;
import com.shine.icis.util.EFRameInf;

/**
 * 基础信息管理->证券公司基本信息文件
 * @author zsy
 *
 */
public class CompanyInfoAction extends BaseAction {

	private static final long serialVersionUID = 7638121893867812633L;
	
	private ICompanyInfoService companyInfoService;
	
	//input param
	private int pageNo;
	private int pageSize;
	private String oldCompanyCode;
	private String companyCode;//证券公司代码
	private String companyName;//证券公司名称
	private String settleInvoCode;//结算参与人代码
	private String ofSaleInvoCode;//基金销售人代码
	private String settleInvoID;//结算参与人清算编号
	private String settleInvoAcctNO;//结算参与人结算账户
	private String occurDate;//
	
	//output param
	private ListPage<CompanyInfo> companyInfoPage;
	
	
	public void setCompanyInfoService(ICompanyInfoService companyInfoService) {
		this.companyInfoService = companyInfoService;
	}

	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public void setOldCompanyCode(String oldCompanyCode) {
		this.oldCompanyCode = oldCompanyCode;
	}

	public void setCompanyCode(String companyCode) {
		this.companyCode = companyCode;
	}

	public void setCompanyName(String companyName) {
		this.companyName = companyName;
	}

	public void setSettleInvoCode(String settleInvoCode) {
		this.settleInvoCode = settleInvoCode;
	}

	public void setOfSaleInvoCode(String ofSaleInvoCode) {
		this.ofSaleInvoCode = ofSaleInvoCode;
	}

	public void setSettleInvoID(String settleInvoID) {
		this.settleInvoID = settleInvoID;
	}

	public void setSettleInvoAcctNO(String settleInvoAcctNO) {
		this.settleInvoAcctNO = settleInvoAcctNO;
	}

	public void setOccurDate(String occurDate) {
		this.occurDate = occurDate;
	}

	
	public ListPage<CompanyInfo> getCompanyInfoPage() {
		return companyInfoPage;
	}

	/**
	 * 转到查询页面
	 * @return
	 */
	public String initQueryCompanyInfo() {
		return success();
	}
	
	/**
	 * 查询
	 * @return
	 */
	public String queryCompanyInfo() {
		QueryParameters qp = new QueryParameters();
		//设置分页信息
		qp.setPageNo(pageNo);
		qp.setPageSize(pageSize);
		try {
			companyInfoPage = companyInfoService.getCompanyInfoPage(qp);
			return success();
		} catch(Exception e) {
			e.printStackTrace();
			return error();
		}
	}
	
	/**
	 * 新增
	 * @return
	 */
	public String addCompanyInfo() {
		if (companyCode == null || companyCode.trim().equals("")
				|| companyName == null || companyName.trim().equals("")
				|| settleInvoCode == null || settleInvoCode.trim().equals("")
				|| ofSaleInvoCode == null || ofSaleInvoCode.trim().equals("")
				|| settleInvoID == null || settleInvoID.trim().equals("")
				|| settleInvoAcctNO == null || settleInvoAcctNO.trim().equals("")
				|| occurDate == null || occurDate.trim().equals("")) {
			return error("参数不能为空");
		}
		boolean success = false;
		try {
			occurDate = occurDate.trim().replaceAll("-", "");
			companyInfoService.addCompanyInfo(companyCode, companyName, settleInvoCode, ofSaleInvoCode, settleInvoID, settleInvoAcctNO, occurDate);
			success = true;
			return success();
		} catch(ICISException e) {
			return error(e.getMessage());
		} catch(Exception e) {
			e.printStackTrace();
			return error();
		} finally {
			SessionParam user = (SessionParam)getSession().getAttribute(SysConstants.SESSION_USER_KEY);
			//记录系统日志
			EFRameInf.saveOpLog(user.getUSER_CODE(), EFRameInf.FUNCCODE_BASEINFO, "增加证券公司基本信息公司代码为[" + companyCode + "]", success);
		}
	}
	
	/**
	 * 修改
	 * @return
	 */
	public String modifyCompanyInfo() {
		if (oldCompanyCode == null || oldCompanyCode.trim().equals("")
				|| companyCode == null || companyCode.trim().equals("")
				|| companyName == null || companyName.trim().equals("")
				|| settleInvoCode == null || settleInvoCode.trim().equals("")
				|| ofSaleInvoCode == null || ofSaleInvoCode.trim().equals("")
				|| settleInvoID == null || settleInvoID.trim().equals("")
				|| settleInvoAcctNO == null || settleInvoAcctNO.trim().equals("")
				|| occurDate == null || occurDate.trim().equals("")) {
			return error("参数不能为空");
		}
		boolean success = false;
		try {
			occurDate = occurDate.trim().replaceAll("-", "");
			companyInfoService.modifyCompanyInfo(oldCompanyCode,companyCode, companyName, settleInvoCode, ofSaleInvoCode, settleInvoID, settleInvoAcctNO, occurDate);
			success = true;
			return success();
		} catch(ICISException e) {
			return error(e.getMessage());
		} catch(Exception e) {
			e.printStackTrace();
			return error();
		} finally {
			SessionParam user = (SessionParam)getSession().getAttribute(SysConstants.SESSION_USER_KEY);
			//记录系统日志
			EFRameInf.saveOpLog(user.getUSER_CODE(), EFRameInf.FUNCCODE_BASEINFO, "修改证券公司基本信息公司代码为[" + oldCompanyCode + "]", success);
		}
	}
	
	/**
	 * 删除
	 * @return
	 */
	public String deleteCompanyInfo() {
		if (companyCode == null || companyCode.trim().equals("")) {
			return error("参数不能为空");
		}
		boolean success = false;
		try {
			companyInfoService.deleteCompanyInfo(companyCode);
			success = true;
			return success();
		} catch(Exception e) {
			e.printStackTrace();
			return error();
		} finally {
			SessionParam user = (SessionParam)getSession().getAttribute(SysConstants.SESSION_USER_KEY);
			//记录系统日志
			EFRameInf.saveOpLog(user.getUSER_CODE(), EFRameInf.FUNCCODE_BASEINFO, "删除证券公司基本信息公司代码为[" + companyCode + "]", success);
		}
	}

}
